package game.commands.app
{
	import com.adobe.serialization.json.JSON;
	
	import flash.utils.ByteArray;
	
	import game.model.scene.SceneProxy;
	
	import org.bulkLoader.comply.BulkLoader;
	import org.bulkLoader.comply.BulkLoaderDefine;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	public class InitConfigDataCommand extends SimpleCommand
	{
		public function InitConfigDataCommand()
		{
			super();
		}
		
		override public function execute(notification:INotification):void
		{
			var loader:BulkLoader = BulkLoaderDefine.getInstance("bulkLoader");
			var datContent:ByteArray = loader.getDataByTitle("configData");
			
			var data:Object;
			try {
				datContent.uncompress();
				data = datContent.readObject();
			} catch (error:Error) {
				datContent.position = 0;
				data = JSON.decode(datContent.readUTFBytes(datContent.length));
			}
			
			var sceneProxy:SceneProxy = facade.retrieveProxy(SceneProxy.NAME) as SceneProxy;
			sceneProxy.setMapGridConfig(data.config_map_grid);
			sceneProxy.setMapConfig(data.config_map);
			sceneProxy.setSceneConfig(data.config_scene);
		}
	}
}